package com.itzz.ssm.contorller;


import com.itzz.ssm.domain.Role;
import com.itzz.ssm.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author:liuweibo
 * @Date Create in 2021/8/11 14:10
 * @Description:
 */
@Controller
@RequestMapping("role")
public class RoleContorller {
    @Autowired
    private RoleService roleService;
    /*查询所有角色*/
    @RequestMapping("findRole")
    public String findRole(HttpServletRequest request){
        List<Role> rolelist = roleService.findRole();
        request.setAttribute("rolelist",rolelist);
        return "/pages/role-list";
    }
    /*添加视图返回*/
    @RequestMapping("addRoleView")
    public  String addRoeViwe(){
        return "/pages/role-add";
    }
    /*添加角色*/
    @RequestMapping("addRole")
    public String addRole(Role role){
        roleService.saveRole(role);
        return "redirect:/role/findRole";
    }
    /*删除角色*/
    @RequestMapping("deleteRole/{id}")
    public String deleteRole(@PathVariable("id") int id){
        roleService.deleteRole(id);
        return "redirect:/role/findRole";
    }

}
